<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<jsp:include page="../head.jsp"></jsp:include>
<head>
<link rel="StyleSheet" href="css/ctreeselector.css" type="text/css" />
<script type="text/javascript" src="scripts/ctreetable.js"></script>
<script type="text/javascript" src="scripts/stringBuffer.js"></script>
<script type="text/javascript" src="scripts/ctreeselector.js"></script>
<script type="text/javascript">
	function selectProductType(va){
		$('#productTypeId').val('');
		$('#pro').val('');
		$.ajax({
			type:"POST",
			url:"TbProductServlet",
			data:"method=getProductTypeByCompanyId&num="+parseInt(Math.random()*(10000000))+"&companyId="+va,
			success:function(datas){
			dr = new cTreeTable('dr',1);
			dr.config.useSelection = true;
			dr.config.rowSelection = false;
			dr.config.closeSameLevel = true;
			dr.config.useChecks = true;
			dr.config.folderChecks = true;
			dr.config.checkSubs = true;
			dr.config.showBadNodes = true;
			//dr.config.stepDepth = 1;
			dr.config.iconPath = '../img/';
			dr.add(0,-1,'产品类型');
			 pArray=datas.split(",");
			  if((pArray!=""))
			  for(var i=0;i<pArray.length;i++){
				  dr.add(pArray[i].split(":")[0],pArray[i].split(":")[1],pArray[i].split(":")[2]);
			  }
			}
			});
	}//end function selectProductType
	//选择界面
	function checkInterface(va){
			document.getElementById(va.value).disabled=!va.checked;
			if(va.checked)document.getElementById(va.value).focus();
			else document.getElementById(va.value).value='';
			setPrice();
	}//end function checkInterface
	function setPrice(){
		var tempArray = document.getElementsByTagName("input");
		var flag=false;
		for(var i =0;i<tempArray.length;i++){
			if(tempArray[i].type=="checkbox"&&tempArray[i].checked)	flag=true;
		}	
		document.getElementById("productPrice").disabled=flag;
		if(flag)document.getElementById("productPrice").value='';
	}//end function setPrice

	//the operator of tree
		
		
		
	function showSelector(inputName) {
		dr.config.useChecks = false;
		var selector = getTreeSelector(dr, 'DIV1', inputName);
		selector.cssfile = "css/ctreeselector.css";
		selector.show();
	}
	
	function showChecker(inputName) {
		dr.config.useChecks = true;
		var selector = getTreeSelector(dr, 'DIV1', inputName);
		selector.cssfile = "css/ctreeselector.css";
		selector.show();
	}
	
	
	function onLoa(){
		$.ajax({
			type:"POST",
			url:"TbProductServlet",
			data:"method=getProductTypeByCompanyId&num="+parseInt(Math.random()*(10000000))+"&companyId=${sessionScope.tbProductPrice==null?0:sessionScope.tbProductPrice.companyId}",
			success:function(datas){
			dr = new cTreeTable('dr',1);
			dr.config.useSelection = true;
			dr.config.rowSelection = false;
			dr.config.closeSameLevel = true;
			dr.config.useChecks = true;
			dr.config.folderChecks = true;
			dr.config.checkSubs = true;
			dr.config.showBadNodes = true;
			dr.config.stepDepth = 1;
			dr.config.iconPath = '../img/';
			//dr.add(0,-1,'产品类型');
			 pArray=datas.split(",");
			  if((pArray!=""))
			  for(var i=0;i<pArray.length;i++){
			      dr.clearCookie();
				  dr.add(pArray[i].split(":")[0],pArray[i].split(":")[1],pArray[i].split(":")[2]);
			  }
			}
			});
	}
	function doSubmit(){
		var productTypeId = $('#productTypeId').val();
		var companyId = $('#companyId').val();
		if(!document.getElementById('cancelCheck').checked){
			$.ajax({
				type:"POST",
				url:"TbCompanyProductTypeMiddleServlet",
				data:"method=getObj&num="+parseInt(Math.random()*(10000000))+"&productTypeId="+productTypeId+"&companyId="+companyId,
				success:function(datas){
				if(datas<1){
					alert("对其没有操作");
					}else
					{
						$('#fmTbProduct').submit();
					}
				}
				});
		}else $('#fmTbProduct').submit();
		
	}
	function cancel_Check(va){
		if(va.checked){
		$('#productTypeId').val('');
		$('#pro').val('');
		}else{
			$('#productTypeId').val('${sessionScope.tbProductPrice.tbProduct.tbProductType.productTypeId }');
			$('#pro').val('${sessionScope.tbProductPrice.tbProduct.tbProductType.productTypeName }');
		}
	}
</script>
</head>
<body onload="onLoa()">
<form id='fmTbProduct'  action="TbProductServlet?method=${sessionScope.tbProductPrice==null?'add':'edit'}" method='post'>
<input type="hidden" name="productPriceMiddleId" id="productPriceMiddleId" value="${sessionScope.tbProductPrice.companyProductMiddleId }"/>
<input type="hidden" name="productId" id="productId" value="${sessionScope.tbProductPrice.productId }"/>
<table>
<tr><td colspan="2" align='center' >${sessionScope.tbProductPrice==null?'添加':'修改'}产品</td></tr>
<tr>
    <td>年份</td>
    <td>
    <input type='text' name='productDate' id='productDate' class="Wdate" size="20"   readonly onclick="WdatePicker({el:this,dateFmt:'yyyy'})" value='${sessionScope.tbProductPrice.productDate }'  />
    </td>
</tr>
<tr>
    <td>公司</td>
    <td>
    <select name='companyId' id='companyId'  onchange="selectProductType(companyId.value)">
		<option value="-1">无</option>
	<c:forEach items="${sessionScope.tbCompanyList}" var="tbCompany" varStatus="status">
		<option value="${tbCompany.companyId }" ${tbCompany.companyId == sessionScope.tbProductPrice.companyId?'selected':''}>${tbCompany.companyName }</option>
	</c:forEach>
</select>
<input type="hidden" name="company_Id" id="company_Id" value="${sessionScope.tbProductPrice.companyId }"/>
</td>
</tr>
<tr>
    <td>产品类型</td>
    <td>
    <input type='text' name='pro' id="pro" class="selectorinput" value="${sessionScope.tbProductPrice.tbProduct.tbProductType.productTypeName }"  readonly onclick="showSelector('productTypeId');" size='25' />
    <input type="hidden" name='productTypeId' id='productTypeId' value="${sessionScope.tbProductPrice.tbProduct.tbProductType.productTypeId }"/>
    <input type="checkbox" name="cancelCheck" id="cancelCheck" onclick="cancel_Check(this)"/>取消类型
    </td>
</tr>
<tr>
    <td>产品名称</td>
    <td><input type='text' name='productName' id='productName' value='${sessionScope.tbProductPrice.tbProduct.productName }' /></td>
</tr>
<tr>
    <td>界面</td>
    <td>
	<c:forEach items="${sessionScope.tbInterfaceList}" var="tbInterface" varStatus="status">
		<input type="checkbox" name="interfaceId" id="interfaceId"  value='${tbInterface.interfaceId  }' 
		${sessionScope.hm[tbInterface.interfaceId]!=null?'checked':''} onclick="checkInterface(this)"/>${tbInterface.interfaceName }
		<input type="text" size="5" id="${tbInterface.interfaceId }" name="${tbInterface.interfaceId }" 
		value="${sessionScope.hm[tbInterface.interfaceId]==null?'':sessionScope.hm[tbInterface.interfaceId]}" ${sessionScope.hm[tbInterface.interfaceId]==null?'disabled':'' }/><br />
	</c:forEach>
	 
    </td>
</tr>
<tr><td>价格</td>
	<td><input type="text" name="productPrice" id="productPrice" value="${sessionScope.tbProductPrice.interfaceId!=0?'':sessionScope.tbProductPrice.productPirce}"/></td>
</tr>
<tr>
    <td>单位</td>
    <td>
	<select name='productUnitId' id='productUnitId' >
		<option value="-1">无</option>
	<c:forEach items="${sessionScope.tbProductUnitList}" var="tbProductUnit" varStatus="status">
		<option value="${tbProductUnit.productUnitId }" ${tbProductUnit.productUnitId == sessionScope.tbProductPrice.productUnitId?'selected':''}>${tbProductUnit.productUnitName}</option>
	</c:forEach>
	</select>
    </td>
</tr>

<tr>
    <td>备注</td>
    <td><input type='text' name='productMemo' id='productMemo' value='${sessionScope.tbProductPrice.tbProduct.productMemo }' /></td>
</tr>
<tr>
    <td colspan='2' align='center' ><input type="button" name="btsubmit" id="btsubmit" onclick="doSubmit()" value="${sessionScope.tbProductPrice==null?'添加':'修改'}" /><input type='reset' value='重置' /><input type='button' value='返回' onclick='history.go(-1);' /></td>
</tr></table>
<div id="DIV1" ></div>
</form>
<script type="text/javascript">
${sessionScope.tbProductPrice==null?'':'setPrice();'}
</script>
<jsp:include page="../foot.jsp"></jsp:include>
</body>
</html>